package week3.day19;

import java.util.Scanner;

/**
 * @Author fengzihao
 * @Date 2024-05-03 19:35
 */
public class NumberFormatExceptionTest {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数字：");
        while (true){
            try {
                String stringNumber = sc.nextLine();
                int number = Integer.parseInt(stringNumber);
                System.out.println("输入正确，输入的数字为： " + number);
                break;
            }catch (NumberFormatException e){
                System.out.println("输入错误，请重新输入：");
            }
        }
    }
}

